package com.xjlsoft.weather.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.xjlsoft.weather.dto.PageDto;
import com.xjlsoft.weather.dto.WeatherDataQueryDto;
import com.xjlsoft.weather.entity.QueryLog;
import com.xjlsoft.weather.mapper.QueryLogMapper;
import com.xjlsoft.weather.service.QueryLogService;
import com.xjlsoft.weather.util.WeatherDataUtil;

import java.sql.Timestamp;

import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
 * <p>
 * 角色表 服务实现类
 * </p>
 *
 * @author zhangbanglong
 * @since 2020-08-04
 */
@Service
public class QueryLogServiceImpl extends ServiceImpl<QueryLogMapper, QueryLog> implements QueryLogService {

	
	@Autowired
	private QueryLogMapper queryLogMapper;
	@Override
	public IPage<QueryLog> getList(PageDto<QueryLog> pagedto,WeatherDataQueryDto weatherDataDto) throws Exception {
		
		QueryWrapper<QueryLog> query = Wrappers.query();
		if(StringUtils.isNotBlank(weatherDataDto.getDateStart())){
			Timestamp timestart=WeatherDataUtil.strToTimestamp(weatherDataDto.getDateStart());
			query.ge("create_time", timestart);
		}
		if(StringUtils.isNotBlank(weatherDataDto.getDateEnd())){
			Timestamp timeend=WeatherDataUtil.strToTimestamp(weatherDataDto.getDateEnd());
			query.le("create_time", timeend);
		}
		
		if(StringUtils.isNotBlank(weatherDataDto.getRequestType())){
			query.eq("request_api_id", weatherDataDto.getRequestType());
		}
		if(StringUtils.isNotBlank(weatherDataDto.getRequestStatus())){
			query.eq("request_data_status", weatherDataDto.getRequestStatus());
		}
		if(StringUtils.isNotBlank(weatherDataDto.getReturnCode())){
			query.eq("return_code", weatherDataDto.getReturnCode());
		}
		query.orderByDesc("create_time");
		
		IPage<QueryLog> list =queryLogMapper.selectPage(pagedto, query);
		
		return list;
	}

}
